package com.you.atlas.web.place.module.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.TurbineRunData;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.AlbumQueryService;
import com.you.atlas.biz.place.service.CommentService;
import com.you.atlas.biz.place.service.PhotoQueryService;
import com.you.atlas.biz.place.service.PlaceQueryService;
import com.you.common.ibatis.data.DataList;
import com.you.place.dal.dao.dataobject.AlbumDO;
import com.you.place.dal.dao.dataobject.PhotoDO;
import com.you.place.dal.dao.dataobject.PlaceDO;

public class PhotoView {

    @Autowired
    private AlbumQueryService albumQueryService;

    @Autowired
    private PhotoQueryService photoQueryService;

    @Autowired
    private PlaceQueryService placeQueryService;

    @Autowired
    private CommentService    commentService;

    public void execute(TurbineRunData rundata,@Param("id") Long albumId, @Param("pageNo") int pageNo, Context context,
                        Navigator navigator) {

        AlbumDO albumDO = albumQueryService.find(albumId);
        if (albumDO == null) {
            navigator.redirectTo("placeModule").withTarget("error.vm");
            rundata.getRedirectLocation();
            return;
        }
        context.put("albumDO", albumDO);
        
        List<PhotoDO> photoList = photoQueryService.queryPhotoByAlbumId(albumId);
        PlaceDO placeDO = placeQueryService.find(albumDO.getPlaceId());
        DataList commentList = commentService.queryByFKId(pageNo, "photo", albumId);
        context.put("photoList", photoList);
        context.put("commentList", commentList);
        context.put("placeDO", placeDO);
    }
}
